<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        div{
            position: absolute;
            top: 0;
            left: 0;
            margin: 50px 0;
            width: 100px;
            height: 100px;
            background-color: red;
        }
    </style>
    <script>
        window.onload = function(){
            function $(selecter){
                return document.querySelector(selecter)
            }
            var moveVal = 0
            var timer = null
            // var target = 500 //目标值
            // var leader = 0 //步长
            $('button').onclick = function(){
                clearInterval(timer)
                timer = setInterval(() => {
                    moveVal+=3
                    $('div').style.left = moveVal+'px'
                    // leader = leader + (target - leader) / 10
                }, 30);
            }
        }
    </script>
</head>
<body>
    <button>点击</button>
    <div></div>
</body>
</html>